import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_framework/widgets/ink_btn.dart';

class LoadingBtn extends StatefulWidget {
  @override
  _LoadingBtnState createState() => _LoadingBtnState();
}

class _LoadingBtnState extends State<LoadingBtn> {
  bool isLoading = false;
  TextEditingController _ctrl = TextEditingController();

  @override
  void dispose() {
    // TODO: implement dispose
    _ctrl.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedContainer(
      duration: const Duration(milliseconds: 400),
      width: isLoading ? 50 : 300,
      height: 50,
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(20)),
      child: InkButton(
          color: Theme.of(context).primaryColor,
          radius: isLoading ? 30 : 10,
          onTap: () {
            setState(() {
              isLoading = !isLoading;
            });
          },
          child: AnimatedSwitcher(
            duration: const Duration(milliseconds: 400),
            child: isLoading
                ? const SizedBox(
              width: 24,
              height: 24,
              child: CircularProgressIndicator(
                color: Colors.white,
                strokeWidth: 3,
              ),
            )
                : Text(
              '登 录',
              style: TextStyle(color: Colors.white),
            ),
          )),
    );
  }
}
